<?php

namespace component\extend\tencentsms;

use component\extend\Isms;
use Exception;
use Noodlehaus\Config;
use Siam\Sms\TencentSms as SmsTencentSms;

class Index implements Isms
{

    public function send(array $param = [])
    {
        $config = Config::load(__DIR__  . '/config.ini');
        $tencenetSms = new SmsTencentSms($config['SecretId'], $config['SecretKey']);

        $result = $tencenetSms
            ->setAppid($config['appid'])
            ->setMobile($param['data']['phone'])
            ->setTemplate($param['msgid'])
            ->setSign($config['sign'])
            ->setParams($param['variable'])
            ->send();

        if (!$result) {
            throw new Exception('');
        }
    }
}
